/* rcdela.p - Deleting active Customer Schedules                              */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.4.1.2 $                                                         */
/*V8:ConvertMode=NoConvert                                                    */
/* REVISION: 8.6          CREATED: 05/01/97   BY: *K0CV* Vinay Nayak-Sujir    */
/* REVISION: 8.6    LAST MODIFIED: 10/15/97   BY: *J232* Niranjan R.          */
/* REVISION: 8.6    LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan           */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown           */
/* $Revision: 1.4.1.2 $    BY: Jean Miller    DATE: 03/22/01 ECO: *P008*        */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* To do all processing related to deletion of an active customer
 * schedule */

{mfdeclre.i}

define input parameter sodrecid   as recid no-undo.
define input parameter schtype       like sch_type no-undo.
define input parameter schmstr_recid as recid no-undo.
define input parameter detail_only   as logical no-undo.

define variable is_req_schd_maint like mfc_logical initial yes no-undo.

/* In case of deleting active reqd ship schd, we need to
 * restore consumed forecast and delete required ship schedules-
 * -related MRP demand records*/

mainblk:
do transaction:

   find sod_det where recid(sod_det) = sodrecid exclusive-lock.

   if schtype = 3 then do:

      /* Update Forecase in Ship-From Database */
      {gprun.i ""rcrsfc.p""
         "(input sodrecid,
           input ""remove"",
           input is_req_schd_maint)"}

      {gprun.i ""rcschdel.p""
         "(input schmstr_recid, input detail_only)"}

      /* Update MRP from Ship-from Database */
      {gprun.i ""rcmrw.p""
         "(input sod_nbr,
           input sod_line,
           input yes)"}

   end. /* if schtype = 3 */

   else do: /* schtype = 1 or 2 */
      {gprun.i ""rcschdel.p""
         "(input schmstr_recid, input detail_only)"}
   end.

   find sch_mstr where recid(sch_mstr) = schmstr_recid
   no-lock no-error.

   /* If sch_mstr is available, deletion failed for some reason */
   if available sch_mstr then
      undo mainblk, leave mainblk.

   assign
      sod_det.sod_curr_rlse_id[schtype] = "".

   /* Update remote DB copy of sod_det, if it exists */
   {gprun.i ""rcrsdup.p"" "(input sodrecid)"}

end. /* mainblk */
